<?php
require_once("getTopCategoriesNameData.php");
if (count($query_result["data"]) != 1) {
    $query_result["code"] = "3033";
    $query_result["msg"] = "请求数据出错!";
    $query_result["data"] = [];
} else {
    $key = "cg_pid";
    $value = $query_result["data"][0]["cg_uuid"];
    $table_name = "categories";
    $no_auto_echo = true;
    require("../../utils/pagination.php");

    /* 对第一次查询的数据进行了处理 后再返回 */
    $new_arr = array_map(function ($item) {
        $uuid = $item['cg_uuid'];
        SQLTools::rowTB($GLOBALS['conn'], "categories");
        if (SQLTools::rowTB($GLOBALS['conn'], "categories", "cg_pid='$uuid'")  > 0) {
            $item['hasChildren'] =  true;
        } else {
            $item['hasChildren'] =  false;
        }
        return $item;
    }, $query_result["data"]);
    $query_result["data"] = $new_arr;
}

echo json_encode($query_result);
